package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendPayMethodAddDTO;
import org.jsola.hr.dto.AttendPayMethodUpdateDTO;
import org.jsola.hr.entity.AttendPayMethodDO;
import org.jsola.hr.query.AttendPayMethodQuery;
import org.jsola.hr.service.IAttendPayMethodService;
import org.jsola.hr.vo.AttendPayMethodVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendPayMethodTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendPayMethodService attendPayMethodService;

    /**
     * 生成add测试数据
     * @return AttendPayMethodAddDTO
     */
    public AttendPayMethodAddDTO getAttendPayMethodAddDTO(){
        AttendPayMethodAddDTO attendPayMethodAddDTO = new AttendPayMethodAddDTO();
        attendPayMethodAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendPayMethodAddDTO.setPayMethod(SafeKit.getInteger(getRandomValue("int",0)));
        attendPayMethodAddDTO.setSpecificWay(SafeKit.getInteger(getRandomValue("int",0)));
        attendPayMethodAddDTO.setHours(SafeKit.getInteger(getRandomValue("int",0)));
        attendPayMethodAddDTO.setDays(SafeKit.getInteger(getRandomValue("int",0)));
        attendPayMethodAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendPayMethodAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendPayMethodUpdateDTO
     */
    public AttendPayMethodUpdateDTO getAttendPayMethodUpdateDTO(AttendPayMethodVO attendPayMethodVO){
        return attendPayMethodService.selectDOById(attendPayMethodVO.getId(), SITE_ID).to(AttendPayMethodUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendPayMethodQuery
     */
    public AttendPayMethodQuery getAttendPayMethodQuery() {
        AttendPayMethodQuery attendPayMethodQuery = new AttendPayMethodQuery();
        List<AttendPayMethodDO> attendPayMethodDOList = attendPayMethodService.list(new AttendPayMethodDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendPayMethodDOList)) {
            AttendPayMethodDO attendPayMethodDO = attendPayMethodDOList.get(0);
            attendPayMethodQuery = attendPayMethodDO.to(AttendPayMethodQuery.class);
            if (attendPayMethodDO.getGmtCreate() != null) {
                attendPayMethodQuery.setGmtCreateStart(DateKit.getBeforeDay(attendPayMethodDO.getGmtCreate(),-1));
                attendPayMethodQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendPayMethodDO.getGmtCreate(),1));
            }
            if (attendPayMethodDO.getGmtModified() != null) {
                attendPayMethodQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendPayMethodDO.getGmtModified(),-1));
                attendPayMethodQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendPayMethodDO.getGmtModified(),1));
            }
        }
        return attendPayMethodQuery;
    }

    /**
     * 保存示例
     * @return AttendPayMethodVO
     */
    public AttendPayMethodVO saveAttendPayMethodExample(){
        AttendPayMethodAddDTO addDTO = this.getAttendPayMethodAddDTO();
        AttendPayMethodVO attendPayMethodVO = attendPayMethodService.save(addDTO,buildTokenUser());
        return attendPayMethodVO;
    }


}

